﻿using Abp.AspNetCore.Configuration;
using Abp.AspNetCore.Mvc.ExceptionHandling;
using Abp.UI;
using Abp.Web.Models;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Net;

namespace Basefr.Web.Filters
{
    public class HttpGlobalExceptionFilter : AbpExceptionFilter
    {
        public HttpGlobalExceptionFilter(IErrorInfoBuilder errorInfoBuilder, IAbpAspNetCoreConfiguration configuration) : base(errorInfoBuilder, configuration)
        {

        }

        protected override int GetStatusCode(ExceptionContext context, bool wrapOnError)
        {
            if (wrapOnError && context.Exception is UserFriendlyException)
            {
                return (int)HttpStatusCode.OK;
            }

            return base.GetStatusCode(context, wrapOnError);
        }
    }
}
